import { GSprite } from "../../../../com/mui/controls/GSprite";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { EquipmentBgItem } from "./EquipmentBgItem";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { GlobalSkin } from "../../../component/skin/GlobalSkin";
import { StrengthAttributePanel } from "./StrengthAttributePanel";
import { ImagesConst } from "../../resource/ImagesConst";
import { DataEvent } from "../../events/DataEvent";
import { ItemData } from "../../resource/info/ItemData";
import { EPlayerItemPosType } from "../../../../Message/Public/EPlayerItemPosType";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { _maxLevel } from "../../../../this/_maxLevel";
type int = number;
//class StrengthInfoPanel
    
    export  class StrengthInfoPanel extends GSprite
    {
        constructor()
        {
            super();
            this.init();
            Dispatcher.addEventListener(EventName.SpiritEquipSelectItem, this.onSpiritEquipSelectItemHandler);
            Dispatcher.addEventListener(EventName.SpiritEquipCancelSelected, this.onSpiritEquipCancelSelectedHandler);
            return;
        }

        /* internal  */init(): void
        {
            this._maxItem = new EquipmentBgItem();
            this._maxItem.move(40, 0);
            addChild(this._maxItem);
            this._item = new EquipmentBgItem();
            this._item.move(165, 30);
            addChild(this._item);
            this._item.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClickHandler);
            var loc1=new GImageBitmap("Label_jipingyulang.png", 10, 40);
            this.addChild(loc1);
            this._maxLevelTxt = ObjCreate.createGTextField("", 230, 75, 50, 20, this, GlobalStyle.getTextFormatCenter(GlobalStyle.textFormatGreen));
            this._strengthBtn = ObjCreate.createGButton(Language.getString(36631), 157, 295, 65, 25, this, GlobalSkin.ButtonRed);
            this._strengthBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onStrengthClickHandler);
            this._attriCurLevelPanel = new StrengthAttributePanel();
            this._attriCurLevelPanel.x = 0;
            this._attriCurLevelPanel.y = 110;
            addChild(this._attriCurLevelPanel);
            this._attriNextLevelPanel = new StrengthAttributePanel();
            this._attriNextLevelPanel.x = 238;
            this._attriNextLevelPanel.y = 110;
            this._attriNextLevelPanel.isStrengthNextLevel = true;
            addChild(this._attriNextLevelPanel);
            this._spiritCoinTxt = ObjCreate.createGTextField("", 150, 210, 90, 20, this);
            this._coinTxt = ObjCreate.createGTextField("", 150, 230, 90, 20, this);
            var loc2=ObjCreate.createBitmap(ImagesConst.spiritCoin, 200, 210, this);
            var loc3=ObjCreate.createBitmap(ImagesConst.Tongqian_small, 200, 233, this);
            return;
        }

        /* internal  */onSpiritEquipSelectItemHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as ItemData;
            this.updateItemData(loc1);
            return;
        }

        /* internal  */onSpiritEquipCancelSelectedHandler(arg1: DataEvent): void
        {
            this.clearPanel();
            return;
        }

        /* internal  */onItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.clearPanel();
            Dispatcher.dispatchEvent(new DataEvent(EventName.SpiritEquipRemoveItem));
            return;
        }

        /* internal  */clearPanel(): void
        {
            this._attriCurLevelPanel.resetShow();
            this._attriNextLevelPanel.resetShow();
            this._maxItem.itemData = null;
            this._item.itemData = null;
            this._spiritCoinTxt.text = "";
            this._coinTxt.text = "";
            return;
        }

        /* internal  */onStrengthClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            if (this._itemData) 
            {
                loc1 = EPlayerItemPosType._EPlayerItemPosTypeRole;
                Dispatcher.dispatchEvent(new DataEvent(EventName.SpiritEquipStrength, {"equipUid": this._itemData.uid, "posType": loc1}));
            }
            return;
        }

        public updateItemData(arg1: ItemData): void
        {
            var loc1=null;
            this._itemData = arg1;
            if (this._itemData) 
            {
                this._maxLevel = this._itemData.itemExInfo.sp_str_max;
                this._item.itemData = this._itemData;
                this._attriCurLevelPanel.updateItemDate(this._itemData);
                if (this._attriCurLevelPanel.level < this._maxLevel) 
                {
                    this._attriNextLevelPanel.updateItemDate(this._itemData);
                    this._spiritCoinTxt.text = this._attriNextLevelPanel.getSpiritCoin() + "";
                    this._coinTxt.text = this._attriNextLevelPanel.getCoin() + "";
                }
                else 
                {
                    this._attriNextLevelPanel.resetShow();
                    this._spiritCoinTxt.text = "";
                    this._coinTxt.text = "";
                }
                this._maxLevelTxt.text = this._maxLevel + "";
                loc1 = new ItemData(this._itemData.itemCode);
                loc1.setItemExInfo({"sp_eq_str": _maxLevel});
                this._maxItem.itemData = loc1;
            }
            return;
        }

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_maxItem: EquipmentBgItem;

        /* internal */ /* var */_item: EquipmentBgItem;

        /* internal */ /* var */_strengthBtn: GButton;

        /* internal */ /* var */_attriCurLevelPanel: StrengthAttributePanel;

        /* internal */ /* var */_attriNextLevelPanel: StrengthAttributePanel;

        /* internal */ /* var */_spiritCoinTxt: GTextFiled;

        /* internal */ /* var */_coinTxt: GTextFiled;

        /* internal */ /* var */_maxLevel: int;

        /* internal */ /* var */_maxLevelTxt: GTextFiled;
    }
